package se.spot4j.model;

import java.net.HttpURLConnection;

import org.apache.http.HttpResponse;

import se.spot4j.exceptions.Spot4JMalformedRequestException;
import se.spot4j.exceptions.Spot4JRateLimitOversteppedException;
import se.spot4j.exceptions.Spot4JServiceUnavailableException;

public class ResponseHandler  {
	
	public void handleResponse(HttpResponse response) throws Spot4JRateLimitOversteppedException, Spot4JMalformedRequestException, Spot4JServiceUnavailableException {
		Integer responseCode = response.getStatusLine().getStatusCode();
		switch(responseCode) {
			case HttpURLConnection.HTTP_FORBIDDEN:
				throw new Spot4JRateLimitOversteppedException();
			case HttpURLConnection.HTTP_BAD_REQUEST:
				throw new Spot4JMalformedRequestException();
			case HttpURLConnection.HTTP_UNAVAILABLE:
				throw new Spot4JServiceUnavailableException();
		}
	}
}
